<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>计算器</title>
		<link rel="stylesheet" type="text/css" href="css/main.css"/>
	</head>
	<body>
		<button onclick="openbox()" id="open">点击</button>
		<div id="box">
			<h1>计算器</h1>
			<span id="close" onclick="closebox()">
				&times;
			</span>
			<hr />
			<input placeholder="请输入数字"  type="text" id="ipt"/>
			<div class="btn-box">
				<input type="button" value="0" onclick="calc('0')"/>
				<input type="button" value="1" onclick="calc('1')"/>
				<input type="button" value="2" onclick="calc('2')"/>
				<input type="button" value="3" onclick="calc('3')"/>
				<input type="button" value="4" onclick="calc('4')"/>
				<input type="button" value="5" onclick="calc('5')"/>
				<input type="button" value="6" onclick="calc('6')"/>
				<input type="button" value="7" onclick="calc('7')"/>
				<input type="button" value="8" onclick="calc('8')"/>
				<input type="button" value="9" onclick="calc('9')"/>
				<input type="button" value="+" onclick="calc('+')"/>
				<input type="button" value="-" onclick="calc('-')"/>
				<input type="button" value="*" onclick="calc('*')"/>
				<input type="button" value="/" onclick="calc('/')"/>
				<input type="button" value="c" onclick="calc('c')"/>
				<input type="button" value="=" onclick="calc('=')"/>
			</div>
		</div>
		
		<script>
			//1.点击 close
			//2.关闭 box
			function closebox(){
				document.getElementById("box").style.display="none";
			}
			function openbox(){
				document.getElementById("box").style.display="block";
			}
			function calc(key){
				var ipt = document.getElementById("ipt");
				switch(key){
					case  "c":
					ipt.value = "";
						break;
						
					case  "=":
					ipt.value = eval(ipt. value);
						break;
					
					default:
					ipt. value += key;
						break;
						
				}
			}
		</script>
	</body>
</html>
